﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ElevatorLib
{
    /// <summary>
    /// Uniform分布
    /// </summary>
    public class UniformDistr : IDistribution
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="rnd">随机数</param>
        /// <param name="max">最大值</param>
        /// <param name="min">最小值</param>
        public UniformDistr(Random rnd, double max, double min)
        {
            if(min >=max)
            {
                min = max = 0;
                throw new Exception("Maximum must be greater than the minimum");
            }
            this.rnd = rnd;
            this.max = max;
            this.min = min;
        }

        #region Properties
        /// <summary>
        /// 随机数
        /// </summary>
        private Random rnd;
        /// <summary>
        /// 最大值
        /// </summary>
        private double max;
        /// <summary>
        /// 最小值
        /// </summary>
        private double min;
        #endregion

        #region IDistribution 成员
        /// <summary>
        /// 生成数据
        /// </summary>
        /// <returns></returns>
        public double Sample()
        {
            double mag = max - min; 
            return (rnd.NextDouble() * (mag)) + min;
        }

        #endregion
    }
}
